﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RuoVea.ExFilter;

namespace RuoVea.OMenuRoleUser.Template.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet(Name = "GetWeatherForecast")]
        public IEnumerable<WeatherForecast> Get()
        {
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }

        /// <summary>
        /// Swagger登录检查 🔖
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [NonRestfulResult]
        [HttpPost("/api/swagger/checkUrl")]
        public int SwaggerCheckUrl()
        {
            return 200;// _httpContextAccessor.HttpContext.User.Identity.IsAuthenticated ? 200 : 401;
        }

        /// <summary>
        /// Swagger登录提交 🔖
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [NonRestfulResult]
        [HttpPost("/api/swagger/submitUrl")]
        public int SwaggerSubmitUrl([FromForm] string userName, [FromForm] string password)
        {
            try
            {
                return 200;
            }
            catch (Exception)
            {
                return 401;
            }
        }
    }
}
